﻿using DGIS.Service.IService.IRenderService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;

namespace DGIS.Service.Service.RenderService
{
    public class FeatureLayerRenderService : IFeatureLayerRenderService
    {
        public IFeatureRenderer CreateClassBreaksRender(string field, Dictionary<double, ISymbol> symbols, List<string> labels)
        {
            IClassBreaksRenderer classBreaksRenderer = new ClassBreaksRendererClass();
            classBreaksRenderer.Field = field;
            classBreaksRenderer.BreakCount = symbols.Count;
            classBreaksRenderer.SortClassesAscending = true;

            for (int i = 0; i < symbols.Count; i++)
            {
                classBreaksRenderer.set_Symbol(i, symbols.ElementAt(i).Value);
                classBreaksRenderer.set_Break(i, symbols.ElementAt(i).Key);

                //构造显示的文字 
                classBreaksRenderer.set_Label(i, labels[i]);
                classBreaksRenderer.set_Description(i, labels[i]);
            }

            return classBreaksRenderer as IFeatureRenderer;
        }

        public IFeatureRenderer CreateUniqueRender(string field, Dictionary<string, ISymbol> symbols, List<string> labels)
        {
            IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass();
            uniqueValueRender.FieldCount = 1;
            uniqueValueRender.set_Field(0, field);

            for (int i = 0; i < symbols.Count; i++)
            {
                uniqueValueRender.AddValue(symbols.ElementAt(i).Key,"",symbols.ElementAt(i).Value);
                uniqueValueRender.set_Label(symbols.ElementAt(i).Key, labels[i]);
            }

            return uniqueValueRender as IFeatureRenderer;            
        }
    }
}
